<%--
  Created by IntelliJ IDEA.
  User: Shisanyang
  Date: 2020/2/6
  Time: 13:45
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<% pageContext.setAttribute("contextPath", request.getContextPath());%>
<html>
<head>
    <title>用户列表</title>
    <script type="text/javascript" src="${contextPath}/static/js/jquery-3.4.1.js"></script>
    <script type="text/javascript">
        function deleteFunction(url)
        {
            console.debug("url = " + url);
            //0、确认删除？
            //1、改变表单的action指向
            //2、提交表单
            if (confirm("确认要删除吗？")) {
                $("#deleteForm").attr("action", url);
                $("#deleteForm").submit();
                alert("删除成功")
            }else {
                alert("删除失败");
            }
        }

    </script>
</head>
<body>
<table border="1" cellpadding="5" cellspacing="0" align="center">
    <tr align="center">
        <th>ID</th>
        <th>LASTNAME</th>
        <th>EMAIL</th>
        <th>GENDER</th>
        <th>BIRTH</th>
        <th>SALARY</th>
        <th>DEPARTMENT</th>
        <th>EDIT</th>
        <th>DELETE</th>
    </tr>
    <c:forEach items="${employeeList}" var="employee">
        <tr align="center">
            <td>${employee.id }</td>
            <td>${employee.lastName }</td>
            <td>${employee.email }</td>
            <td>${employee.gender }</td>
            <td>${employee.birth.toString()}</td>
            <td>${employee.salary }</td>
            <td>${employee.department }</td>
            <td><a href="${contextPath}/emp/${employee.id}">edit</a></td>
            <td>
                <a href="javascript:void(0);" onclick="javascript:deleteFunction('${contextPath}/emp/${employee.id}');return false;" class="deleteBtn">delete</a>
            </td>
        </tr>
    </c:forEach>
</table>
<form action="${contextPath}/toAddPage" enctype="application/x-www-form-urlencoded">
    <input type="submit" value="添加员工"/>
</form>
<form id="deleteForm" method="post">
    <input type="hidden" name="_method" value="DELETE"/>
</form>
<form action="${contextPath}/quickadd">
    <input name="employeeInfo" value="张三-zhangsan@163.com-1-2019/11/12-1000.20-101" />
    <input type="submit" value="快速添加"/>
</form>
</body>
</html>
